package com.equipment;

import java.util.NoSuchElementException;

import com.util.EncodingUtil;

/**
 * 微波收发指令解析
 * @author mln
 *
 */
public class WaveSendResponse {

	private String code = "B5"; // 代码
	private String status = "";
	private String RSSI = "";
	private String info = "";
	private String recvIndex = "";
	private String dsrcData = "";
	private String BCC = "";// 异或校验

	/**
	 * 解析B5
	 * @param context
	 * @return
	 * @throws NoSuchElementException
	 */
	public WaveSendResponse analysis(String context) throws NoSuchElementException{
		WaveSendResponse waveResponse = null;
		if (!code.equals(context.substring(10, 12))) {
			throw new NoSuchElementException("微波收发返回帧指令错误");
		}
		status = context.substring(12, 14);
		if (!status.equals("00")) {
			throw new NoSuchElementException("微波收发指令返回失败:"+status);
		}
		BCC = context.substring(context.length()-2);
		if (!EncodingUtil.yihuo(EncodingUtil.change(context.substring(4, context.length()-2))).equals(BCC)) {
			throw new NoSuchElementException("微波收发指令BCC失败");
		}
		try {
			waveResponse = new WaveSendResponse();
			waveResponse.status = status;
			waveResponse.RSSI = context.substring(16, 18);
			//waveResponse.info = context.substring(18, 20);//add
			waveResponse.recvIndex = context.substring(18, 20);//
			waveResponse.dsrcData = context.substring(20, context.length()-2);//
			waveResponse.BCC = BCC;
		} catch (Exception e) {
			throw new NoSuchElementException("微波收发指令返回失败");
		}
		return waveResponse;
	}

	public String getStatus() {
		return status;
	}

	public String getRSSI() {
		return RSSI;
	}

	public String getInfo() {
		return info;
	}

	public String getRecvIndex() {
		return recvIndex;
	}

	public String getDsrcData() {
		return dsrcData;
	}

	public String getBCC() {
		return BCC;
	}

}
